package com.dolphin.common.component.var.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author shida
 */

@Getter
public enum CalculationEnum {
    SUM("sum", "求和", Integer.valueOf(1), 0),
    MAX("max", "最大值", Integer.valueOf(2), 0),
    MIN("min", "最小值", Integer.valueOf(3), 0),
    AVG("avg", "平均值", Integer.valueOf(4), 0),
    COUNT("count", "次数", Integer.valueOf(5), 0),
    TOP("top", "Top", Integer.valueOf(6), 0),
    COUNTI_SUM("conti_sum", "连续求和", Integer.valueOf(7), 0),
    COUNTI_COUNT("conti_count", "连续次数", Integer.valueOf(8), 0),
    DISCOUNT("disCount", "去重次数", Integer.valueOf(9), 0),
    DISTINCT("distinct", "去重求值", Integer.valueOf(30), 0),
    LAST_INDEX_1("lastindex", "倒数第1条", Integer.valueOf(10), 1),
    TOP_N_MAX("topMax", "最大N条", Integer.valueOf(31), 0),
    TOP_N_MIN("topMin", "最小N条", Integer.valueOf(32), 0),
    LAST_INDEX("lastIndex", "最近几条", Integer.valueOf(33), 0)
    ;

    private String code;
    private String description;
    private Integer id;
    private Integer value;

    CalculationEnum(String code, String description, Integer id, Integer value) {
        this.code = code;
        this.description = description;
        this.id = id;
        this.value = value;
    }

    public static CalculationEnum formString(String calculationType){
        if(StringUtils.isEmpty(calculationType)){
            return null;
        }

        for(CalculationEnum item : values()){
            if(item.name().equals(calculationType)){
                return item;
            }
        }

        return null;
    }
}
